package com.company;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexExample {

    public static void main(String[] params) {

//        (?:pattern)

//// ?:0|1;  *:0|n  +:1|n
//        String line = "TS1234*TS*1234isorderwasTQ12345orTW67895OK?";
//        String pattern = "(.{5})(?:TQ|TW|TS)";
//            if (line.matches(pattern)){
//                System.out.println("Found value" );
//            }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }
//1234*TS
//1234*
//erwasTQ
//erwas
//345orTW
//345or

////        (?=pattern)
//// ?:0|1;  *:0|n  +:1|n
//        String line = "abcdefgh";
//        String pattern = ".(?=cde)..";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }

////        (?=pattern)
//
//// ?:0|1;  *:0|n  +:1|n
//        String line = "TS1234*TS*1234isorderwasTQ12345orTW67895OK?";
//        String pattern = "(.{5})(?=TS|TQ|TW)";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }
//1234*
//1234*
//erwas
//erwas
//345or
//345or

//        (?!pattern)
// ?:0|1;  *:0|n  +:1|n
        String line = "abcdcdeghk";
        String pattern = ".(?!cde)..";
        if (line.matches(pattern)){
            System.out.println("Found value" );
        }
//        Pattern r = Pattern.compile(pattern);
//        Matcher m = r.matcher(line);
        Matcher m = Pattern.compile(pattern).matcher(line);
        while (m.find()) {
            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
                System.out.println(m.group(i));
            }
        }
////        (?!pattern)
//
//        // ?:0|1;  *:0|n  +:1|n
//        String line = "Windows 95 Windows 98 Windows NT Windows 3.1";
//        String pattern = "Windows (?!95|98|NT|2000)";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }


////        (?<=pattern)
//// ?:0|1;  *:0|n  +:1|n
//        String line = "abcdefgh";
//        String pattern = ".(?<=cde)..";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }

////        ((?<=pattern))
//
//        // ?:0|1;  *:0|n  +:1|n
//        String line = "95 Windows1  98 Windows2  NT Windows3  3.1 Windows2 ";
//        String pattern = "(?<=95|98|NT|2000)(.{9})";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }

////        ((?<!pattern))
//
//        // ?:0|1;  *:0|n  +:1|n
//        String line = "95 Windows 98 Windows NT Windows 3.1 Windows";
//        String pattern = "(?<!=95|98|NT|2000) Windows";
//        if (line.matches(pattern)){
//            System.out.println("Found value" );
//        }
////        Pattern r = Pattern.compile(pattern);
////        Matcher m = r.matcher(line);
//        Matcher m = Pattern.compile(pattern).matcher(line);
//        while (m.find()) {
//            for(int i=0;i<=m.groupCount();i++){//这里 i<m.groupCount();改成i<=m.groupCount();
//                System.out.println(m.group(i));
//            }
//        }

//        matches() 方法用于检测字符串是否匹配给定的正则表达式。
//        // 按指定模式在字符串查找
//        String line = "This order was placed for QT3000! OK?";
//
//// \d 匹配一个数字字符。等价于 [0-9]。
//// \D 匹配一个非数字字符。等价于 [^0-9]。
//// ?:0|1;  *:0|n  +:1|n
////        ([^0-9]0|n)([0-9]1|n)([除换行符（\n、\r）之外的任何单个字符 ]0|n)
//        String pattern = "\\D*(\\d+)(.*)";
//       // 创建 Pattern 对象
//        Pattern r = Pattern.compile(pattern);
//
//        // 现在创建 matcher 对象
//        Matcher m = r.matcher(line);
//        if (m.find( )) {
//            System.out.println("Found value: " + m.group(0) );
//            System.out.println("Found value: " + m.group(1) );
//            System.out.println("Found value: " + m.group(2) );
//            System.out.println("Found value: " + m.group(3) );
//        } else {
//            System.out.println("NO MATCH");
//        }

//
////        https://www.runoob.com/regexp/regexp-metachar.html
////        https://www.runoob.com/java/java-regular-expressions.html
////        123456789.1234 只能输入最大整数（允许正负的话就是9位）8位，小数4位 的字符串
//        String[] strArr = new String[]{"-", "-0", "-00000000", "-00000", "-00000.", "-1", "-0001", "-00001", "", ".",
//                "00000000...", "00000000.", "00000000.0000", "00000000.00000", "000000000.0000", "000000000.00000",
//                "123456781234", "1234.", ".1234", "0.123", "00.1234", "000.12345", "00000000.12345", "00000000.1234",
//                "-.123", "0012.05678900000", "0012.567800000",
//                "12345678.1234111", "", "12345aaa.1234", "1aaabbb",
//                "12345678.1234", "11.", "1", "1111.0001", "+1111.0001",
//                "-12345678.1234", "+12345678.1234"};
//        Integer maxintlen = 2;
//        Integer maxdecimallen = 1;
//        Boolean result;
//        for (String str0 : strArr
//        ) {
//            // 先判断是否数字  //正则表达式中？*+的说明： ?:0|1;  *:0|n  +:1|n
//            result = str0.matches("[-]?[0-9]+[\\.]?[0-9]*");
//            if (result == true) {
//                if (str0.contains(".")) {
//                    result = str0.matches("[-]?[0-9]{1," + maxintlen + "}[\\.]?[0-9]{0," + maxdecimallen + "}");
//                } else {
//                    result = str0.matches("[-]?[0-9]{1," + maxintlen + "}");
//                }
//                System.out.println(str0 + "----->>>>>" + result);
////                // 是数字
////                // 去掉开头0->>0012.05678900000->>12.05678900000
////                tempStr= str0.replaceAll("^(0+)", "");
////                 if (tempStr.contains(".")){
////                     // 是小数 例如 12.05678900000  //  去掉末尾0 12.05678900000->>12.056789
////                     tempStr = tempStr.replaceAll("(0)+$", "");
////                }else {
////                    // 是整数
////                     tempStr=str0;
////                }
////                //  最末尾是点，就去掉这个点
////                tempStr = tempStr.replaceAll("(\\.)+$", "");
////                result=tempStr.matches("[-]?[0-9]{1,"+maxintlen+"}[\\.]?[0-9]{0,"+maxdecimallen+"}");
//
//            } else {
//                if (str0.equals("")) {
//                    System.out.println(str0 + "----->>>>>" + "非数値,是空");
//                } else {
//                    System.out.println(str0 + "----->>>>>" + "非数値");
//                }
//
//            }
//        }


    }
}
